/**
 * 格式化日期
 * @param format
 * @param date
 * @param lang
 * @returns {number|string}
 */
export function formatDate(format, date, lang) {
    let myDate;
    if (date) {
        myDate = new Date(date);
    } else {
        myDate = new Date();
    }

    let myYear = myDate.getFullYear(); // 获取当前年份
    let myMonth = myDate.getMonth() + 1; // 获取当前月份
    if (myMonth < 10) {
        myMonth = '0' + myMonth;
    }
    let myDay = myDate.getDate(); // 获取当前日（1- 31）
    if (myDay < 10) {
        myDay = '0' + myDay;
    }
    let myHours = myDate.getHours(); // 获取当前小时(0-23)
    if (myHours < 10) {
        myHours = '0' + myHours;
    }
    let myMinu = myDate.getMinutes(); // 获取当前分钟(0-59)
    if (myMinu < 10) {
        myMinu = '0' + myMinu;
    }
    let mySec = myDate.getSeconds() // 获取当前秒数(0-59)
    if (mySec < 10) {
        mySec = '0' + mySec;
    }

    switch (format) {
        case 'Y':
            if ('zh' === lang) {
                return myYear + '年';
            }
            return myYear
            break;
        case 'Y/m':
            if ('zh' === lang) {
                return myYear + '年' + myMonth + '月';
            }
            return myYear + '-' + myMonth;
            break;
        case 'Y/m/d':
            if ('zh' === lang) {
                return myYear + '年' + myMonth + '月' + myDay + '日';
            }
            return myYear + '-' + myMonth + '-' + myDay;
            break;
        case 'm/d':
            if ('zh' === lang) {
                 return myMonth + '月' + myDay + '日';
            }
            return myMonth + '-' + myDay;
            break;
        case 'Y/m/d/H/i':
            if ('zh' === lang) {
                return myYear + '年' + myMonth + '月' + myDay + '日 ' + myHours + ':' + myMinu;
            }
            return myYear + '-' + myMonth + '-' + myDay + ' ' + myHours + ':' + myMinu;
            break;
        case 'Y/m/d/H/i/s':
            if ('zh' === lang) {
                return myYear + '年' + myMonth + '月' + myDay + '日 ' + myHours + ':' + myMinu + ':' + mySec;
            }
            return myYear + '-' + myMonth + '-' + myDay + ' ' + myHours + ':' + myMinu + ':' + mySec;
            break;
        case 'H/i':
            return myHours + ':' + myMinu;
            break;
        case 'H/i/s':
            return myHours + ':' + myMinu + ':' + mySec;
            break;
        case 'm/d/H/i':
            if ('zh' === lang) {
                return myMonth + '月' + myDay + '日 ' + myHours + ':' + myMinu;
            }
            return myMonth + '-' + myDay + ' ' + myHours + ':' + myMinu;
            break;
    }
}